package dynamicProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JDKDynamicProxy implements InvocationHandler {
    private Person person;

    public JDKDynamicProxy(Person person) {
        this.person = person;
    }

    public Object getTarget() {
        return Proxy.newProxyInstance(person.getClass().getClassLoader(), person.getClass().getInterfaces(), this);
    }

    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
        System.out.println("before");
        Object invoke = method.invoke(person, objects);
        System.out.println("after");
        return invoke;
    }
}
